package user.web.controller;

import domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import serivce.UserService;

import java.util.Collection;


/**
 * Created by Administrator on 2017/11/26.
 */
@RestController
public class UserRestApiController {
    @Autowired
    private UserService userService;
    @PostMapping("/user/save")
    public User save(@RequestParam String name){
        User user = new User();
        user.setName(name);
        if(userService.save(user)){
            return user;
        }
        return null;
    }
    @GetMapping("/user/list")
    public Collection<User> list(){
        return  userService.findAll();
    }
}
